package com.hzw.saas.common.verify.util;

import java.util.Map;
import java.util.Objects;

import cn.hutool.core.io.resource.ResourceUtil;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zzl
 * @since 09/02/2021
 */
@UtilityClass
@Slf4j
public class TemplateUtil {

    public static String getTemplate(String templatePath) {
        try {
            String template = ResourceUtil.readUtf8Str(templatePath);
            log.debug("已加载邮件模板: {}", templatePath);
            return template;
        } catch (Exception e) {
            log.error("未找到邮件模板: {}", templatePath);
            return "";
        }
    }

    public static String getContentByTemplate(String template, Map<String, String> templateParams) {
        if (Objects.nonNull(templateParams)) {
            for (Map.Entry<String, String> entry : templateParams.entrySet()) {
                template = template.replace(entry.getKey(), entry.getValue());
            }
        }
        return template;
    }


}
